// shopPages/shoplist/shoplist.js
var sliderWidth = 70;
var app = getApp();
var selectedNews = false;
var newsList = [];
var page = 1;
Page({
  /**
   * 页面的初始数据
   */
  data: {  
    
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var title = '';
    page = 1;
   

    wx.setNavigationBarTitle({
      title: '拼团',
    })
  
    selectedNews = false;
    newsList = [];

    that.getGoodsList();
  },
  //获取商品列表
  getGoodsList: function () {
    var that = this;

    // 
    var url2 = '/mall/spell_activity';
    var param  ={}
    param.pageno = page;
    param.pagesize = 10;
    wx.showLoading({
      title: '玩命加载中',
    })
    // console.log(param);return false;
    app.HttpPostSend(url2, param, function (res) {
      console.log(res)
      if (res.msg != "success") {
        app.showTipMsg(res.msg);
        selectedNews = false;
        that.setData({
          goodsList: []
        })
      } else {
        var goodsList = res.data;
        for (let i = 0; i < goodsList.length; i++) {
          newsList.push(goodsList[i]);
        }
        if (goodsList.length < 10) {
          selectedNews = false;
        } else {
          selectedNews = true;
          page += 1;
          
        }
        that.setData({
          goodsList: newsList
        })

      }
      wx.hideLoading();
    });
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // },
  onReachBottom: function () {

    if (selectedNews == true) {
      var that = this;
      // 显示加载图标  
      // wx.showLoading({
      //   title: '玩命加载中',
      // })
      // 页数+1  
      that.getGoodsList();

    } else {
      wx.hideLoading();
    }
  },
  toGoodsDetail_: function (e) {
    wx.navigateTo({
      url: "/shopPages/goodsDetailSpell/goodsDetailSpell?id=" + e.currentTarget.dataset.id + '&s_id=' + e.currentTarget.dataset.s_id
    })
  }
})